/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/19/12
 * Time: 12:10 AM
 */
Ext.override(Ext.ZIndexManager, {
    tempHidden: [],
    show: function() {
        var comp, x, y;
        while (comp = this.tempHidden.shift()) {
            x = comp.x;
            y = comp.y;
            comp.show();
            comp.setPosition(x, y);
        }
    }
});


Ext.override(Ext.data.Connection, {

    disableCaching : false,
    timeout: 1200000,
    // private
    onComplete : function(request){

        var me = this,
            options = request.options,
            result,
            success,
            response;

        try {
            result = me.parseStatus(request.xhr.status);
        } catch (e) {
            // in some browsers we can't access the status if the readyState is not 4, so the request has failed
            result = {
                success : false,
                isException : false
            };
        }
        success = result.success;

        if (success) {
            response = me.createResponse(request);

            //Se agregan estas lineas para poder redireccionar al index una vez que los datos de session
            //han caducado

            var ress= Ext.decode(response.responseText);
            if(Ext.type(ress)=="object" && !Ext.isEmpty(ress) && !Ext.isEmpty(ress.fatal)){
                //si se recibio un mensaje fatal, no queda de otra mas que sacarlo del sistema
                if (!Ext.isEmpty(ress.fatal)){
                    Ext.Msg.show({
                        title:'Lo sentimos, ha ocurrido un problema de conexi&oacute;n con el servidor',
                        msg: ress.fatal,
                        buttons: Ext.Msg.OK,
                        fn: function (){
                            window.location.href="index.php";
                        },
                        icon: Ext.MessageBox.WARNING
                    });
                }
            }





            me.fireEvent('requestcomplete', me, response, options);
            Ext.callback(options.success, options.scope, [response, options]);
        } else {
            if (result.isException || request.aborted || request.timedout) {
                response = me.createException(request);
            } else {
                response = me.createResponse(request);
            }
            me.fireEvent('requestexception', me, response, options);
            Ext.callback(options.failure, options.scope, [response, options]);
        }
        Ext.callback(options.callback, options.scope, [options, success, response]);
        delete me.requests[request.id];
        return response;
    }
});